package com.fingard.dsp.bank.directbank.specialDeal;

import java.sql.Connection;
import java.util.Map;

import com.fingard.FGBiz;
import com.fingard.db.JDBCHelper;

public class SimulateHelper {

    private static String qryPayState = "select transstate,payinfocode from paysttcfg where bankcode=? and transtype=? and paystate=?";
    private static String qryBillState = "select b.billstate from commonbillstate a inner join directbillstate b on a.stateid=b.stateid where b.bankcode=? and a.type=? and a.flag=?";

    public String transState = "";
    public String payInfoCode = "";
    public String billState = "";

    public void getFail(String p_bankCode, String p_transType) throws Exception {
        Connection dbConn = null;
        try {
            dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();
            Map<String, Object> payStateMap = JDBCHelper.execQuerySingle(dbConn, qryPayState, new Object[]{p_bankCode, p_transType, "3"});
            if (payStateMap != null && payStateMap.size() > 0) {
                this.transState = String.valueOf(payStateMap.get("transstate"));
                this.payInfoCode = String.valueOf(payStateMap.get("payinfocode"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (dbConn != null) {
                dbConn.close();
            }
        }
    }

    public void getSuccess(String p_bankCode, String p_transType) throws Exception {
        Connection dbConn = null;
        try {
            dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();
            Map<String, Object> payStateMap = JDBCHelper.execQuerySingle(dbConn, qryPayState, new Object[]{p_bankCode, p_transType, "2"});
            if (payStateMap != null && payStateMap.size() > 0) {
                this.transState = String.valueOf(payStateMap.get("transstate"));
                this.payInfoCode = String.valueOf(payStateMap.get("payinfocode"));
            } else {
                payStateMap = JDBCHelper.execQuerySingle(dbConn, qryPayState, new Object[]{p_bankCode, p_transType, "4"});
                if (payStateMap != null && payStateMap.size() > 0) {
                    this.transState = String.valueOf(payStateMap.get("transstate"));
                    this.payInfoCode = String.valueOf(payStateMap.get("payinfocode"));
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (dbConn != null) {
                dbConn.close();
            }
        }
    }

    public void getBillState(String p_bankCode, String p_operateType, String p_operateFlag) throws Exception {
        Connection dbConn = null;
        try {
            dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();
            Map<String, Object> payStateMap = JDBCHelper.execQuerySingle(dbConn, qryBillState, new Object[]{p_bankCode, p_operateType, p_operateFlag});
            if (payStateMap != null && payStateMap.size() > 0) {
                this.billState = String.valueOf(payStateMap.get("billstate"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (dbConn != null) {
                dbConn.close();
            }
        }
    }

}
